<?php

namespace addons\litestore\controller\api;

use app\common\controller\Api;
use addons\litestore\model\Wxlitestoregoods;
use addons\litestore\model\Litestorenews;
use think\Db;

class Index extends Api
{
	protected $noNeedLogin = ['*'];

	public function _initialize()
    {
        parent::_initialize();
    }

	public function index()
    {
    	$Temp_litestoregoods = new Wxlitestoregoods();
        $banner = new Litestorenews();
        $bannerdata = $banner->where('status', 'normal')->order('updatetime', 'desc')->limit(10)->select();
        $bannerList = [];
        foreach ($bannerdata as $index => $item) {
            $bannerList[] = ['image' => cdnurl($item['image'], true), 'title' => $item['title'],'id'=> $item['id'],'good_id'=>$item['good_id']];
        }

//        $NewList = $Temp_litestoregoods->getNewList();
//        foreach ($NewList as $index => $item) {
//            $NewList[$index]['ImageFrist'] = cdnurl(explode(",",$item['images'])[0], true);
//        }

//        $Randomlist = $Temp_litestoregoods->getRandom8();
//        foreach ($Randomlist as $index => $item) {
//            $Randomlist[$index]['ImageFrist'] = cdnurl(explode(",",$item['images'])[0], true);
//        }

        //获取分类模块
        $modlist = $Temp_litestoregoods->getModList();

        //获取图标模块
        $iconlist = $Temp_litestoregoods->getIconList();


        //中部上
        $index1 = $Temp_litestoregoods->getIndex1();

        //中部中
        $index2 = $Temp_litestoregoods->getIndex2();

        //中部下
        $index3 = $Temp_litestoregoods->getIndex3();



        $this->success('', [
//    							'NewList' => $NewList,
//								'Randomlist' => $Randomlist,
                                'bannerlist' => $bannerList,
                                'modList' => $modlist,
                                'iconList' => $iconlist,
                                'index1' => $index1,
                                'index2' => $index2,
                                'index3' => $index3
    					  ]);
    }

    public function getnew(){
        $new_id = $this->request->request('new_id');
        $newdata = Litestorenews::get($new_id);
        $newdata['image'] =  cdnurl($newdata['image'], true);
        $newdata['updatetime'] = datetime($newdata['updatetime']);
        $this->success('', [
                                'newdata' => $newdata
                          ]);
    }


    public function getIcons(){
        $new_id = $this->request->request('new_id');
        $newdata = Db::name('litestore_icon')->where(['id'=>$new_id])->find();
        $newdata['image'] =  cdnurl($newdata['image'], true);
        $newdata['updatetime'] = datetime($newdata['updatetime']);
        $this->success('', [
            'newdata' => $newdata
        ]);
    }

    public function getIndex1(){
        $new_id = $this->request->request('new_id');
        $newdata = Db::name('litestore_index_center1')->where(['id'=>$new_id])->find();
        $newdata['image'] =  cdnurl($newdata['image'], true);
        $newdata['updatetime'] = datetime($newdata['updatetime']);
        $this->success('', [
            'newdata' => $newdata
        ]);
    }

    public function getIndex2(){
        $new_id = $this->request->request('new_id');
        $newdata = Db::name('litestore_index_center2')->where(['id'=>$new_id])->find();
        $newdata['image'] =  cdnurl($newdata['image'], true);
        $newdata['updatetime'] = datetime($newdata['updatetime']);
        $this->success('', [
            'newdata' => $newdata
        ]);
    }

    public function getIndex3(){
        $new_id = $this->request->request('new_id');
        $newdata = Db::name('litestore_index_center3')->where(['id'=>$new_id])->find();
        $newdata['image'] =  cdnurl($newdata['image'], true);
        $newdata['updatetime'] = datetime($newdata['updatetime']);
        $this->success('', [
            'newdata' => $newdata
        ]);
    }

}


